<template>
  <div>
    <!-- 大客户报备审核-->
    <TopFilter ref="topform" :list="topFilterList" :cols="3" @filterChange="changeHandle" @resetChange="changeHandle" :labelWidth="110" />
    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTables
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :maxHeight="800"
        :datakey="'records'"
        columnsRef="KeyCustomerInfoVerify"
        :isSelectColumn="false"
        :onColumnsChange="(columns) => (this.columns = columns)"
      >
      </FilterTables>
    </Spin>
    <Drawer :visible.sync="detailVisible" :title="'大客户报备信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" width="72%">
      <detailModel :type="deailType" :rowData="formData" @close="detailcloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { getLevelOneArea } from '@/api/cms-common/dealerdata/index';
import { region } from '@/api/cms-common/region';
import { getList, deleteBigCustomer } from '@/api/omSaleP/KeyCustomers/KeyCustomerInfoVerify/index.js';
import { exportExcelFile } from '@/utils';
import detailModel from './detailModel';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'KeyCustomerInfoVerify',
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        isDealer: 10041002,
      },
      fetchApi: getList,
      formData: {},
      deailType: '',
      exportLoading: false,
      issearch: false,
      detailVisible: false,
    };
  },
  components: {
    detailModel,
  },
  mixins: [dictionary, region],
  mounted() {
    //初始化所属区域数据
    this.getTopLevelArea();
    //初始化省份数据
    this.initProvince();
  },
  created() {},
  methods: {
    changeHandle(params) {
      this.fetchParams = { ...this.fetchParams, ...params };
    },
    // 所属区域
    async getTopLevelArea() {
      const res = await getLevelOneArea(15061015);
      if (res.resultCode === 200) {
        this.topFilterList.find((item) => item.fieldName === 'areaId').itemList = res.data.map((x) => ({ value: parseInt(x.id), text: x.orgName }));
      }
    },
    //初始化所在省份
    async initProvince() {
      let pl = await this.createRegionList();
      this.topFilterList.find((item) => item.fieldName === 'provinceId').itemList = pl;
    },
    //初始化所在市数据
    async initCity(provinceId) {
      this.topFilterList.find((item) => item.fieldName == 'cityId').initialValue = '';
      this.topFilterList.find((item) => item.fieldName == 'cityId').itemList = [];
      if (!provinceId || provinceId == null || typeof provinceId == 'undefined') {
        return;
      }
      //取省数据
      let rd = this.getRegionData();
      this.cityData = rd[provinceId].children;
      let cl = this.createSubRegionList(this.cityData);
      //初始化市，清除原值
      let city = this.topFilterList.find((item) => item.fieldName === 'cityId');
      city.itemList = cl;
      city.initialValue = '';
    },
    // 数据操作
    async editHandle(row, type) {
      //编辑、明细
      this.deailType = type;
      this.detailVisible = true;
      this.formData = row;
    },
    detailcloseHandler() {
      this.detailVisible = false;
      if (this.deailType !== 'detail') {
        this.fetchParams = { ...this.fetchParams };
      }
    },
    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: '大客户编号',
          fieldName: 'customersNo',
          maxlength: '10000',
          placeholder: '输入多个大客户编号时，请用英文逗号或者换行隔开（例如：编号1,编号2……）',
          maxRows: 2,
        },
        {
          type: 'INPUT',
          label: '大客户名称',
          placeholder: '请输入',
          fieldName: 'customersName',
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'status',
          placeholder: '请选择',
          itemList: this.createDictList('2146').filter((item) => item.value != '21461001'),
        },
        {
          type: 'SELECT',
          label: '所属区域',
          fieldName: 'areaId',
          placeholder: '请选择',
          itemList: [],
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'provinceId',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
          change: (props) => this.initCity(props),
        },
        {
          type: 'SELECT',
          label: '城市',
          fieldName: 'cityId',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
        },
        {
          type: 'TEXT_AREA',
          label: '经销商代码',
          placeholder: '输入多个经销商代码时，请用“,”隔开',
          fieldName: 'dealerCode',
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          placeholder: '请输入',
          fieldName: 'dealerName',
        },
        {
          type: 'SELECT',
          label: '大客户来源',
          fieldName: 'customersType',
          placeholder: '请选择',
          itemList: this.createDictList('2108'),
        },
        {
          type: 'RANGE_DATE',
          label: '提报日期',
          fieldName: 'reportDateBeginDate|reportDateEndDate',
          placeholder: '请选择日期',
          initialValue: '',
          format: 'yyyy-MM-dd',
          dateType: 'exactdaterange',
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          // width: 100,
          algin: 'center',
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" disabled={props.row.status !== 21461002} onClick={() => this.editHandle(props.row, 'examine')}>
                  审核
                </multiuse-button>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 'detail')}>
                  明细
                </multiuse-button>
              </div>
            );
          },
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.status, '2146')}</span>;
          },
        },
        {
          title: '大客户来源',
          dataIndex: 'customersType',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.customersType, '2108')}</span>;
          },
        },
        {
          title: '报备有效开始时间',
          dataIndex: 'startDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd',
        },
        {
          title: '报备有效结束时间',
          dataIndex: 'endDate',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd',
          filterType: 'input',
        },
        {
          title: '所属区域',
          dataIndex: 'areaName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '大客户编号',
          dataIndex: 'customersNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '大客户名称',
          dataIndex: 'customersName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '运营单位联系人',
          dataIndex: 'contactsName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '运营单位联系电话',
          dataIndex: 'customerPhone',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '联系地址',
          dataIndex: 'addressName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '提报人',
          dataIndex: 'reportPersonName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '提报时间',
          dataIndex: 'reportDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd',
        },
        {
          title: '审核人',
          dataIndex: 'auditName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '审核时间',
          dataIndex: 'auditTime',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd',
        },
      ];
    },
  },
};
</script>